# set是无序的（不保证顺序性）
# my_set = set()
# 这样定义的是一个 空 字典
my_set = {}
# <class 'dict'> {}
print(type(my_set), my_set)

my_set = {1, 2, 3, 3, 2, 1}
print(my_set)

# 添加元素
my_set.add('Python')
print(my_set)

# 移除元素
my_set.remove(3)
print(my_set)

# 随机取出一个元素
res = my_set.pop()
print(my_set, res)

# 取集合的差集
my_set1 = {1, 2, 3}
my_set2 = {1, 5, 6}
# 不会改变原先的集合内容
my_set3 = my_set1.difference(my_set2)
print(my_set1)
print(my_set2)
print(my_set3)

# 移除my_set1中相同的元素，会改变 1 中的元素
my_set1.difference_update(my_set2)
print(my_set1)
print(my_set2)

# 集合的合并
print("=====集合的合并=====")
my_set1 = {1, 2, 3}
my_set2 = {1, 5, 6}
my_set3 = my_set1.union(my_set2)
print(my_set1)
print(my_set2)
print(my_set3)

# 集合的长度
print(len(my_set3))

print("=====集合的遍历=====")
for i in my_set3:
    print(i)
